module.exports = function ($scope, $state, $stateParams, $resource, $modal, center_list) {

	//下拉菜单
	$scope.sel = center_list;
	
	//搜索列表
	$scope.search = function () {
		$scope.all = false;
		var para = {
			'center_code': $scope.search.item.value,
			'center_key': $scope.search.item.key
		};
		$resource('/api/ac/sc/systemFunction/isSync', {}, {}).get(para, function(res){
			if(res.errcode === 0){
				$scope.apiList = res.data;
				for(var i = 0; i < $scope.apiList.length; i++){
					if($scope.apiList[i].statusCode == 3){
						$scope.apiList[i].btn = 'btn btn-sm btn-default btn-rounded disabled';
					}else{
						$scope.apiList[i].btn = 'btn btn-sm btn-success btn-rounded';
					}
				}
			}else{
				alert(res.errmsg);
			}
        });
	};

	//全部选择框
	$scope.setSelect = function () {
		if($scope.all){
			for(var i=0;i<$scope.apiList.length;i++){
				$scope.apiList[i].check = true;
			}
		}else{
			for(var i=0;i<$scope.apiList.length;i++){
				$scope.apiList[i].check = false;
			}
		}
	};

	//同步
	$scope.sync = function (item) {
		var list = [];
		if(item == undefined){
			for(var i = 0; i < $scope.apiList.length; i++){
				if($scope.apiList[i].check == true){
					list.push($scope.apiList[i])
				}
			}
		}else{
			list.push(item);
		}
		$resource('/api/ac/sc/systemFunction/updateSysFun', {}, {}).save({'list': list}, function (res) {
			if (res.errcode === 0) {
				$scope.search();
			} else {
				alert(res.errmsg);
			}
		});
	}


};